#ifndef _I2C_H_
#define _I2C_H_

#include <typedef.h>

void i2c_init(void);
void i2c_master_transmit(u8, u8, u8);
void i2c_master_receive(u8, u8, u8 *data);
void i2c_irq(void);

#define WRDATA      (1)
#define RDDATA 		(3)
#define SETRDADDR 	(4)

#define IICBUFSIZE	 0x20

/* I/O Port Control */
#define GPECON			(*((volatile unsigned long *)(0x56000040)))

/* I2C Register */
#define	IICCON			(*((volatile unsigned long *)(0x54000000)))
#define	IICSTAT			(*((volatile unsigned long *)(0x54000004)))
#define	IICADD			(*((volatile unsigned long *)(0x54000008)))
#define	IICDS			(*((volatile unsigned long *)(0x5400000C)))
#define	IICLC			(*((volatile unsigned long *)(0x54000010)))

/* IICCON bits */
#define IICCON_ACK_EN        (1<<7)
#define IICCON_TCLK_PCLK512  (1<<6)
#define IICCON_INT_EN        (1<<5)
#define IICCON_INT_PEND      (1<<4)
#define IICCON_TCLK			 (0xf)

/* IICSTAT bits */
#define IICSTAT_MTX_MODE      (3<<6)
#define IICSTAT_MRX_MODE      (2<<6)
#define IICSTAT_STX_MODE      (1<<6)
#define IICSTAT_SRX_MODE      (0<<6)
#define IICSTAT_BUSY          (1<<5)
#define IICSTAT_OUT_EN        (1<<4)
#define IICSTAT_ARB_FAILED    (1<<3)
#define IICSTAT_SLAVEADDR     (1<<2)
#define IICSTAT_ADDRZERO      (1<<1)
#define IICSTAT_NACK          (1<<0)
#define IICSTAT_MRX_ENABLE (IICSTAT_MRX_MODE | IICSTAT_BUSY | IICSTAT_OUT_EN)
#define IICSTAT_MTX_ENABLE (IICSTAT_MTX_MODE | IICSTAT_BUSY | IICSTAT_OUT_EN)

#define IIC_INT_CMD_NONE              0
#define IIC_INT_CMD_TXSTOP            1
#define IIC_INT_CMD_RXSTOP            2
#define IIC_INT_CMD_RESTART           3
#define IIC_INT_CMD_WRITE_DATA        4
#define IIC_INT_CMD_WRITE_DATA_END    5
#define IIC_INT_CMD_READ_PRE_DATA     6
#define IIC_INT_CMD_READ_DATA         7

#endif //_I2C_H_
